<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<h2>运动新闻订阅</h2>
<div id="msg"></div>
<script src="js/stomp.min.js"></script>
<script>
    //创建websocket
    const ws = new WebSocket('ws://localhost:8080/message-broker');
    //再将websocket对象包装成STOMP客户端
    const stomp = Stomp.over(ws);
    //设置发出心跳的间隔时间(单位：ms)
    stomp.heartbeat.outgoing = 30000;
    //设置接收心跳的间隔时间（单位：ms）
    stomp.heartbeat.incoming = 30000;
    //连接服务器并订阅消息
    stomp.connect({},function (){
        //订阅消息
        stomp.subscribe('/sports/message', function (data) {
            const msg = JSON.parse(data.body);
            //获取消息内容
            document.getElementById('msg').innerHTML += msg.content+'<br>';
        })
    })

</script>
</body>
</html>